package com.crowdfunding.controller;

import com.crowdfunding.bean.Cert;
import com.crowdfunding.service.CertService;
import com.crowdfunding.service.CertTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("certType")
@Controller
public class CertTypeController extends BaseController {
    @Autowired
    private CertTypeService certTypeService;
    @Autowired
    private CertService certService;
    @RequestMapping("index")
    public String index(Map<String,Object>map){
        List<Cert> allCert=certService.quertAllCert();
        map.put("allCert",allCert);
        List<Map<String,Object>>certAccttypeList=certTypeService.queryCertAccttype();
        map.put("certAccttypeList",certAccttypeList);
        return "certType/index";
    }

    @ResponseBody
    @RequestMapping("addCertAccttype")
    public Object addCertAccttype(Integer certid,String accttype){
        start();
        try{
            Map<String,Object>param=new HashMap<>();
            param.put("certid",certid);
            param.put("accttype",accttype);
            Integer count=certTypeService.addCertAccttype(param);
            success(count==1);
        }catch (Exception e){
         e.printStackTrace();
         success(false);
         message("新增资质关系异常");
        }
        return end();
    }
    @ResponseBody
    @RequestMapping("deleteCertAccttype")
    public Object deleteCertAccttype(Integer certid,String accttype){
        start();
        try{
            Map<String,Object>param=new HashMap<>();
            param.put("certid",certid);
            param.put("accttype",accttype);
            Integer count=certTypeService.deleteCertAccttype(param);
            success(count==1);
        }catch (Exception e){
            e.printStackTrace();
            success(false);
            message("删除资质关系异常");
        }
        return end();
    }
}
